<?php defined("MAIN_DIR") or die("No direct access");

$bank_id = UV::readInt($route->getPath(3));

$bank_res = mysql_query("select `bank_id`,`name` from `bank` where `bank_id` = '$bank_id' limit 1");
if (mysql_num_rows($bank_res) == 0) {
	to("/admin/boxes/");
}

$bank_row = mysql_fetch_array($bank_res);

require_once ADMIN.HEADFILE;
?>
<div align="left">
<h1>Список ячеек - <?php echo $bank_row['name']; ?></h1><?php
$box_query = "select `box_id`,`address` from `box` where `bank_id` = '$bank_row[bank_id]'";

$limit = 10;
$box_res = mysql_query($box_query);
$count = mysql_num_rows($box_res);
$page = 1;
if (isset($_GET['page']))
	$page = $_GET['page'];
$max_page = ceil($count/$limit);
if ($max_page == 0)
	$max_page++;
if ($page > $max_page)
	$page = $max_page;
elseif ($page < 1)
	$page = 1;
$start_list = (ceil($page)-1)*$limit;
$box_query .= " limit $start_list,$limit";
$box_res = mysql_query($box_query);
$box_count = mysql_num_rows($box_res);
?>
<table cellpadding="5" cellspacing="0" class='light'>
	<tr id='header'>
		<td width="30px" style="border-bottom:1px gray solid">ID</td>
		<td width="300px" style="border-bottom:1px gray solid">Адрес</td>
		<td width="200px" style="border-bottom:1px gray solid">Действия</td>
	</tr><?php
	while ($box_row = mysql_fetch_array($box_res))
	{
		?><tr>
			<td><?php echo $box_row['box_id']?></td>
			<td><?php echo $box_row['address']?></td>
			<td>
				<a href='/admin/boxes/edit/<?php echo $box_row['box_id']?>'>Редактировать</a> |
				<a onclick='return confirm_del()' href='/admin/boxes/delete/<?php echo $box_row['box_id']?>'>Удалить</a>
			</td>
		</tr><?php
	}
?></table>
<br /><a href='/admin/boxes/add/?bank_id=<?php echo $bank_row['bank_id'];?>'>Добавить ячейку</a>
<br />
<br /><a href='/admin/boxes/'>Назад</a><br /><?php require_once APP."pageskin.php"; ?>
</div>

<?php require_once ADMIN.FOOTERFILE; ?>